<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="科室名字" >
        <el-input
          v-model="queryParams.depOffName"
          placeholder="请输入科室名字"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button   type="success" icon="el-icon-plus" size="mini" @click="newAdd">新增</el-button>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="search" style="margin-left: 10px">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="科室名字"   property="depOffName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="科室编码" property="depOffNo" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"

            @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button
            size="mini"
            type="danger"

            icon="el-icon-delete"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />
    <el-dialog
      :title="name"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="400px">
      <el-form :model="newParams" ref="newParams" :inline="true" label-width="100px" :rules="rules">
        <el-form-item label="科室名字" prop="depOffName">
          <el-input
            v-model="newParams.depOffName"
            placeholder="请输入科室名字"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="科室编码" prop="depOffNo">
          <el-input
            v-model="newParams.depOffNo"
            placeholder="请输入科室编码"
            clearable
            size="small"
          />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="determineBtn">确 定</el-button>
  </span>
    </el-dialog>

  </div>
</template>

<script>
  import request from '@/utils/request'

  export default {
    name: "Role",
    components:{

    },
    data() {
      return {
        // 表单校验
        rules: {
          depOffName: [
            { required: true, message: "科室名字不能为空", trigger: "blur" }
          ],
          depOffNo: [
            { required: true, message: "科室编码不能为空", trigger: "blur" }
          ],
        },
        newParams:{
          depOffName:'',
          depOffNo:'',
          id:'',
        },
        name:'新增物料科室',
        dialogVisible:false,
        xqjhShow:false,
        xqjhStr:{},
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [ ],
        // 菜单列表
        menuOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          depOffName: '',
        },
        // 表单参数
        form: {},
        leixng:'post'
      };
    },
    created() {
      this.search()

    },
    methods: {
      //新增 修改确定
      determineBtn:function(){
        if(!this.newParams.depOffName){
          this.$message({
            type: 'warning',
            message: '科室名字不能为空'
          });
          return
        }
        if(!this.newParams.depOffNo){
          this.$message({
            type: 'warning',
            message: '科室编码不能为空'
          });
          return
        }
        request({
          url: '/system/off',
          method: this.leixng,
          data:this.newParams
        }).then(response => {
          this.dialogVisible = false
          this.$message({
            type: 'success',
            message: '新增成功!'
          });
          this.search()

        });
      },
      //新增
      newAdd:function(){
        this.newParams.depOffName=''
        this.newParams.depOffNo=''
        this.leixng = 'post'
        this.name='新增物料科室'
        this.dialogVisible = true

      },
      //查询
      search:function(){
        this.loading = true
        request({
          url: '/system/off/list',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading =false
          this.roleList = response.rows
          this.total = response.total
        });
      },

      //表格修改
      handleEdit:function (index,row) {
        console.log(row)
        this.newParams.depOffName=row.depOffName
        this.newParams.depOffNo=row.depOffNo
        this.newParams.id =row.id
        this.leixng = 'put'
        this.name='修改物料科室'
        this.dialogVisible = true
      },
      //删除
      handleDelete:function (index,row) {
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
         this.shanchu(row)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      //删除
      shanchu:function (id) {
        request({
          url: '/system/off/' + id.id,
          method: 'delete',
          params:this.queryParams
        }).then(response => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.search()
        });
      },

    }
  };
</script>
